<?php
// @formatter:off
/**
 * @file s.comics.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-05-13 04:08:49 +0000 (Mon, 13 May 2013) $
 *
 * $Id: s.comics.php 64 2013-05-13 04:08:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/services/s.comics.php $
 */
// @formatter:on

$wcServiceStatus = false;
$wcServiceErrorCode = 500;

if(defined('__SERVICE__')) {
	if($_SERVER["REQUEST_METHOD"] == "POST") {
		if($wcComic && $wcComic->ok()) {
			if(isset($_POST["NEXT_NAME"]) && $wcProfile->allowedTo(WC_PERM_COMIC_RENAME)) {
				$next = trim($_POST["NEXT_NAME"]);
				$name = explode(".", $wcComic->next_name ? $wcComic->next_name : $wcComic->name);
				$ext = array_pop($name);
				$name = implode(".", $name);

				if(!$next) {
					$wcServiceErrorMsg = "No new name specified";
				} elseif($next == $name) {
					$wcServiceErrorMsg = "New name is the same than current one";
				} else {
					$wcServiceStatus = true;
					$wcComic->next_name = "{$next}.{$ext}";
				}
			} elseif(!$wcProfile->allowedTo(WC_PERM_COMIC_RENAME)) {
				$wcServiceErrorCode = 403;
				$wcServiceErrorMsg = "Unable to access service";
			} else {
				$wcServiceErrorMsg = "This service was call with invalid parameters";
			}
		} else {
			$wcServiceErrorMsg = "This service was call with invalid parameters";
		}
	} else {
		$wcServiceErrorCode = 403;
		$wcServiceErrorMsg = "This service only works on POST method";
	}
} else {
	$wcServiceErrorCode = 403;
	$wcServiceErrorMsg = "Unable to access service";
}
?>